import 'package:flutter/material.dart';
import 'package:flutter_dk_form/flutter_dk_form.dart';

class DkDropDownButtonFormField extends DkFormField<String> {
  DkDropDownButtonFormField({
    Key key,
    @required String attribute,
    InputDecoration decoration = const InputDecoration(),
    String initialValue,
    bool readOnly = false,
    ValueChanged<String> onChanged,
    DkFormFieldValidator<String> validator,
    ValueTransformer valueTransformer,
    List<String> list,
  }) : super(
    attribute: attribute,
    initialValue: initialValue,
    validator: validator,
    valueTransformer: valueTransformer,
    builder: (DkFormFieldState<String> field) {
      final DkFormFieldState state = field;
      void onChangedHandler(value) {
        if (onChanged != null) {
          onChanged(value);
        }
        field.didChange(value);
      }

      return InputDecorator(
        decoration: state.selfShowError?decoration.copyWith(errorText: state.errorText):decoration,
        child: DropdownButton(
          isExpanded: true,
          items: (parsePara(state.parameter)??list).map((option) {
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!! $option");
            return DropdownMenuItem(
              child: Text("$option"),
              value: option,
            );
          }).toList(),
          onChanged: onChangedHandler,
          value: state.value,
        ),
      );
    },
  );


  static List parsePara(dynamic para){

    print("parsePara $para");
    return para;
  }
}